<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="java.sql.*"%>
<%
	request.setCharacterEncoding("UTF-8");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>学生登陆注册</title>
</head>
<body>

	<%
		try {
			Class.forName("com.mysql.jdbc.Driver");
			String url = "jdbc:mysql://localhost:3306/jsp";
			String dataBaseUsername = "root"; 
			String dataBasePassword = "root"; 
			Connection conn = DriverManager.getConnection(url, dataBaseUsername, dataBasePassword);
			
			
			String id=request.getParameter("id");
			String password=request.getParameter("password");
			
			if(conn!=null){
				String sql="select * from tb_student where id="+ id +" and password="+ password +" ";
				Statement stmt = conn.createStatement();
				ResultSet rs=stmt.executeQuery(sql);
				if(rs.next()){
					response.sendRedirect("home.jsp");				
				}else{
					out.print("用户名或密码错误，请重新输入！");
					%>
					<a href="javascript:history.back()">返回</a>
					<% 
				}			
				
				conn.close();
			}else{
				
				out.println("数据库连接失败！");						
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	%>
</body>
</html>